package com.zhipu.resetbalance.utils;

import android.view.Gravity;

import com.blankj.utilcode.util.ColorUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.raizlabs.android.dbflow.config.FlowConfig;
import com.raizlabs.android.dbflow.config.FlowLog;
import com.raizlabs.android.dbflow.config.FlowManager;
import com.zhipu.resetbalance.BaseApplication;
import com.zhipu.resetbalance.R;
import com.zhipu.resetbalance.common.Constants;
import com.zhipu.resetbalance.remotedata.AppComponent;
import com.zhipu.resetbalance.remotedata.DaggerAppComponent;
import com.zhipu.resetbalance.remotedata.SpModule;
import com.zhipu.resetbalance.remotedata.systemapi.SystemApiServiceModule;
import com.zhipu.resetbalance.utils.serialPort.WeightSerialPortUtils;
import com.zhipuchina.signature.SignV0;

public class InitializeUtils {
    /**
     *  上下文
     */
    private static BaseApplication MBaseApplication;
    public static BaseApplication getMBaseApplication() {
        return MBaseApplication;
    }
    public static void setMBaseApplication(BaseApplication MBaseApplication) {
        InitializeUtils.MBaseApplication = MBaseApplication;
    }




    /**
     * Toast设置统一样式
     */
    private static ToastUtils defaultMaker;
    public static ToastUtils getDefaultMaker() {
        return defaultMaker;
    }
    public static void initDefaultMaker() {
        defaultMaker = ToastUtils.getDefaultMaker();
        defaultMaker.setBgColor(ColorUtils.getColor(R.color.color_00BFFF));
        defaultMaker.setGravity(Gravity.CENTER,0,0);
        defaultMaker.setTextColor(ColorUtils.getColor(R.color.color_FFFFFF));
        defaultMaker.setTextSize(36);
    }



    /**
     * 初始化DBFlow
     */
    public static void initializeDBFlow(BaseApplication mBaseApplication){
        //初始化DBFlow
        FlowManager.init(new FlowConfig.Builder(mBaseApplication).build());
        //设置日志显示
        FlowLog.setMinimumLoggingLevel(FlowLog.Level.D);
    }



    /**
     * 日志相关
     */
    public static void initializeLogUtils(){
        LogUtils.Config config = LogUtils.getConfig();
        //设置 log 总开关
        config.setLogSwitch(true);
        //设置 log 文件开关
        config.setLog2FileSwitch(true);
        //设置 log 可保留天数
        config.setSaveDays(5);
        // 设置 log 文件存储目录
        config.setDir(Constants.LogPath);
    }


    /**
     * 初始化
     */
    private static AppComponent mAppComponent;
    public static AppComponent getAppComponent() {
        return mAppComponent;
    }
    public static void setAppComponent(BaseApplication mBaseApplication) {
        mAppComponent = DaggerAppComponent.builder().systemApiServiceModule(new SystemApiServiceModule()).spModule(new SpModule(mBaseApplication)).build();
    }


    /**
     * 串口初始化
     */
    public static void initGorge(){
        //
        WeightSerialPortUtils.initSerialPortOpen();
    }

    /**
     * 签名
     */
    private static SignV0 mSignV0;
    public static SignV0 getSignV0(){
        return mSignV0;
    }

    public static void initSign(BaseApplication baseApplication) {
        if (mSignV0 == null) {
            mSignV0 = new SignV0();
            mSignV0.signatureVerify(baseApplication);
        }
    }
}
